#include "StudentArray.h"


StudentArray::StudentArray(void)
{
	m_pStudentVec = new vector<Student*>();
}


StudentArray::~StudentArray(void)
{
	vector<Student*>::iterator ite = m_pStudentVec->begin();
	while (ite != m_pStudentVec->end())
	{
		delete (*ite);
		ite++;
	}
}

void StudentArray::Attach(Student *pStu)
{
	m_pStudentVec->push_back(pStu);
}

void StudentArray::Detach(Student *pStudent)
{
	vector<Student*>::iterator ite = m_pStudentVec->begin();
	while (ite != m_pStudentVec->end())
	{
		if ((*ite) == pStudent)
		{
			ite = m_pStudentVec->erase(ite);
		}
		else
		{
			ite++;
		}
	}
}

void StudentArray::SetVisitor(IVisitor *pVisitor)
{
	m_pVisitor = pVisitor;
}

void StudentArray::AllPayMoney()
{
	vector<Student*>::iterator ite = m_pStudentVec->begin();
	while (ite != m_pStudentVec->end())
	{
		(*ite)->Accept(m_pVisitor);
		ite++;
	}
}
